package com.myapp.blueslave;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;

public class ShowPatterns extends View {
    private SurfaceHolder holder;
    private boolean hasSurface;
    private Paint paint;  
    private int flag = 0;
    public int counter = 5;
    private int y=20;
    private int T1=65;
    private int T2=50;
    private int T3=55;
    private int T4=60;
    private int colorTop = Color.WHITE;
    private int colorLeft = Color.BLACK;
    private int colorRight = Color.WHITE;
    private int colorBottom = Color.BLACK;
    private int i = 5, j;
    private int screenHeight, screenWidth;
    //private TimerTop timerTop;
    private String str = "";

    public ShowPatterns(Context context) {
        super(context);
        paint = new Paint();
        DisplayMetrics metrics = new DisplayMetrics();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
        screenHeight = metrics.heightPixels;
        screenWidth = metrics.widthPixels;
        setBackgroundColor(Color.BLACK);
        Log.d("BouncingBallView", "Values "+T1+" "+T2+" "+T3+" "+T4);
        paint.setTextSize(40);
        paint.setTypeface(Typeface.create("Times new roman", Typeface.BOLD));
     }
    
     // Called back to draw the view. Also called by invalidate().
     @Override
     protected void onDraw(Canvas canvas) {
    
  	   j = 0;
         
         //this.setBackgroundColor(Color.GRAY);
         paint.setColor(colorTop);
         canvas.drawRect(screenWidth/2-30, 0, screenWidth/2+30, 30, paint);
         paint.setColor(colorLeft);
         canvas.drawRect(0, screenHeight/2-30, 30, screenHeight/2+30, paint);
         paint.setColor(colorRight);
         canvas.drawRect(screenWidth-30, screenHeight/2-30, screenWidth, screenHeight/2+30, paint);
         paint.setColor(colorBottom);
         canvas.drawRect(screenWidth/2-30, screenHeight-30, screenWidth/2+30, screenHeight, paint);
         
         if(i % T1 == 0){
                 if(colorTop == Color.WHITE)colorTop = Color.BLACK;
                 else colorTop = Color.WHITE;
                 j++;
                 //Log.d("BouncingBallActivity", "Test"+T1);
         }
         if(i % T2 == 0){
                 if(colorLeft == Color.WHITE)colorLeft = Color.BLACK;
                 else colorLeft = Color.WHITE;
                 j++;
                 //Log.d("BouncingBallActivity", "Test"+T2);
         }
         if(i % T3 == 0){
                 if(colorRight == Color.WHITE)colorRight = Color.BLACK;
                 else colorRight = Color.WHITE;
                 j++;
                 //Log.d("BouncingBallActivity", "Test"+T3);
         }
         if(i % T4 == 0){
                 if(colorBottom == Color.WHITE)colorBottom = Color.BLACK;
                 else colorBottom = Color.WHITE;
                 j++;
                 //Log.d("BouncingBallActivity", "Test"+T4);
         }
         try {  
            Thread.sleep(5);  
         } catch (InterruptedException e) {Log.d("BouncingBallActivity", "Exception"); }
         i+=counter;
         if(j == 4 || (i % 42900 == 0))i = 5;
         //Log.d("BouncingBallView", "i="+i+"  j="+j);
         invalidate();  // Force a re-draw
         canvas.drawText(getString(), screenWidth/2-50, screenHeight/2+10, paint);
         //Log.d("ShowPatterns", "String12:"+str);
     }
     
     public void setString(String txt){
    	 str = txt;
    	 //Log.d("ShowPatterns", "String:"+str);
    	 showString();
     }
     
     public String getString(){
    	 return str;
     }
     
     public void showString(){
    	 Log.d("ShowPatterns", "String:"+getString());
     }
}